//
//  ViewController.swift
//  YSM
//
//  Created by ys on 2018/7/13.
//  Copyright © 2018年 ys. All rights reserved.
//

import UIKit

class SecondViewController: BaseViewController {
    
    private var label: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.initData()
        self.initView()
        self.registerNotify()
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let vc = YSRouter.loadVC(vcName: "ThirdViewController")
        vc.loadVCInfo(params:["title":"三级页面"])
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    override func loadVCInfo(params: Any) {
        let para = params as? Dictionary<String, Any>
        self.navigationItem.title = para?["title"] as? String
    }
    
    override func reciveRouterCommon(name: Notification.Name, params: Any?) {
        if name == .RLoginSucess {
            self.label.text = params as? String ?? "已回调传值无参数"
            print("\(self.classForCoder) 登录成功 回调 \(params ?? "无参数")")
        }else if name == .RLogout {
            self.label.text = params as? String ?? "已回调传值无参数"

            print("\(self.classForCoder) 退出登录 回调 \(params ?? "无参数")")
        }
    }
    
    private func initData() {
        
    }
    
    private func initView() {
        self.label = UILabel(frame: CGRect(x: 50, y: 100, width: 200, height: 40))
        self.label.text = "点击页面跳转"
        self.view.addSubview(self.label)
        
    }
    
    private func registerNotify() {
        YSRouterCommon.addRouterCommon(names: .RLogout, .RLoginSucess, target: self)
    }
    
    @objc private func loginSuccess(notifi:Notification) {
        print(notifi.name)
        self.navigationItem.title = notifi.object as? String
    }


}
